package com.open4cn.simulator.config.controller;

import com.open4cn.simulator.device.DeviceStatusManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yinxiaopeng
 * @version 1.0.0
 * @company 致景科技
 * @department 飞梭BU/研发
 * @description
 * @Email yinxiaopeng@zj.tech
 * @date 2022-05-20 11:28
 */
@RestController
@RequestMapping("manager/status")
public class DeviceStatusManagerController {

    @GetMapping("/{deviceId}")
    public Object get(@PathVariable("deviceId") String deviceId) {
        return DeviceStatusManager.getInstance().get(deviceId);
    }

    @GetMapping("/persistence/{deviceId}")
    public Object persistence(@PathVariable("deviceId") String deviceId) {
        DeviceStatusManager deviceStatusManager = DeviceStatusManager.getInstance();
        deviceStatusManager.persistence(deviceId);
        return deviceStatusManager.get(deviceId);
    }

    @GetMapping("/change/{deviceId}")
    public Object change(@PathVariable(name = "deviceId") String deviceId,
                         @RequestParam(name = "key") String key,
                         @RequestParam(name = "value") String value) {
        DeviceStatusManager deviceStatusManager = DeviceStatusManager.getInstance();
        deviceStatusManager.changeStatus(deviceId, key, value);
        return deviceStatusManager.get(deviceId);
    }


}
